package com.gx.server.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gx.server.common.BaseResponse;
import com.gx.server.common.ErrorCode;
import com.gx.server.common.ResultUtils;
import com.gx.server.model.domain.ExamQuestion;
import com.gx.server.model.service.ExamQuestionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Dobby
 * @version 1.0
 */

@RestController
@RequestMapping("/ExamQuestion")
@Slf4j
public class ExamQuestionController {

    @Autowired
    ExamQuestionService examQuestionService;

    /**
     * 返回所有题目信息
     * @return
     */
    @GetMapping("/all")
    public BaseResponse<List<ExamQuestion>> allExamQuestion(int subject){
        List<ExamQuestion> examQuestions = examQuestionService.all_question(subject);
        return ResultUtils.success(examQuestions);
    }


    @GetMapping("/assign")
    public BaseResponse<List<ExamQuestion>> assignQuestion ( int number,  int type,  int subject, int question_type){
        List<ExamQuestion> examQuestions = examQuestionService.assign_question(number, type, subject, question_type);

        if (examQuestions == null) return ResultUtils.error(ErrorCode.NULL_ERROR,"没有这种题目");

        return ResultUtils.success(examQuestions);
    }

    @GetMapping("/number")
    public BaseResponse<Integer> numberQuestion(){
        return ResultUtils.success(examQuestionService.number_question());
    }

    @GetMapping("/rand")
    public BaseResponse<List<ExamQuestion>> rand_question(Long userId,int number, int type,int subject){
        return ResultUtils.success(examQuestionService.rand_question(userId,number,type,subject));
    }


    /**
     * 根据用户id 查询所有的错误题目
     * @param id
     * @return
     */
    @GetMapping("/Error")
    public BaseResponse<List<ExamQuestion>> all_Errors(Long id){
        List<ExamQuestion> examQuestions = examQuestionService.all_Errors(id);

        if (examQuestions.size()==0) return ResultUtils.error(ErrorCode.NULL_ERROR);
        return ResultUtils.success(examQuestions);
    }


}
